*This file estimates the local capital accumulation by reparations exposure and creates Table A.3 

*Import local data
use "$path/industry_forregs.dta", clear

*Combine the two municipalities in the dataset.
*Jämsä expands in 1960 when Jämsänkoski gains a paper factory (Jämsänkoski is subsequently merged). Combine these two municipalities.

preserve
replace code=183 if code==182
collapse (sum) horsepower , by(code year)
rename  horsepower horsepower_treat
tempfile jamsa
save `jamsa'
restore

drop if code==182
joinby code year using `jamsa'
replace horsepower=horsepower_treat  if code==183
drop  horsepower_treat

winsor2 horsepower, cuts(1 99) by(year)
gen horsepower_old=horsepower

gen ln_horsepower=ln(horsepower+1)
gen ln_horsepower_w=ln(horsepower_w+1)
gen ihs_horsepower=ln(horsepower + sqrt( horsepower^2 + 1))

sort code year

*Define controls

preserve
keep if year==1943

set seed 1608
elasticnet linear bartik_st ln_pop_1940 agrishare_a1940 manushare_a1940  ln_workersmean_1943 ln_valueadded_1943 ln_salary_1943 ln_otherpersonnel_1943 ln_grossvalueproduct_1943 ln_factorynumber_1943 swedish_share_1940 share_service_1940 relative_tractors1940 relative_cows1940 ln_arable_1940 ln_pop_1940 income_tax_payers38 relative_tractors1940 displaced_share_1940 

lassoinfo
lassocoef
restore 

global enet_12  c.ln_pop_1940#year c.agrishare_a1940#year  c.swedish_share_1940#year  c.ln_grossvalueproduct_1943#year c.relative_cows1940#year c.income_tax_payers38#year c.displaced_share_1940#year 

*Table for ln horsepower +1 (A.1)

local repaflexible1 "bartik_post"

foreach x in ln_horsepower  ln_horsepower_w ihs_horsepower {
reghdfe `x' `repaflexible1' [aw=wei] ,a(year#laani50 $enet_12 year year#city year#town code)  vce(cluster code) 
estadd local enet "\checkmark"
estadd local Municipalities " 198 "
estadd local established "Yes"

estimates store b`x' 
}

**Hig and low skill exposure

local repaflexible1 "bartik_h_post bartik_l_post"

foreach x in ln_horsepower ln_horsepower_w ihs_horsepower {
reghdfe `x' `repaflexible1' [aw=wei] ,a(year#laani50 $enet_12 year year#city year#town code)  vce(cluster code) 
estadd local enet "\checkmark"
estadd local Municipalities " 198 "
estadd local established "Yes"

estimates store bhl`x' 
}

*Without established

preserve 
replace bartik_post=bartik_ntp_st_post
foreach x in ln_horsepower ln_horsepower_w ihs_horsepower {
reghdfe `x' bartik_post [aw=wei] ,a(year#laani50  $enet_12 year#city  year#town code)  vce(cluster code) 
estadd local enet "\checkmark"
estadd local established "No"

estadd local Municipalities " 198 "
estimates store bntp`x' 
}
restore 

*Calibrated extensive margin

gen ln_horsepower_nz=ln(horsepower)

preserve 
replace ln_horsepower_nz=-3 if horsepower==0
reghdfe ln_horsepower_nz bartik_post [aw=wei] ,a(year#laani50 $enet_12 year year#city year#town code)  vce(cluster code) 
estadd local em "3"
estadd local enet "\checkmark"
estadd local Municipalities " 198 "
estadd local established "Yes"
estimates store em1 
restore 

preserve 
replace ln_horsepower_nz=-1 if horsepower==0
reghdfe ln_horsepower_nz bartik_post [aw=wei] ,a(year#laani50 $enet_12 year year#city year#town code)  vce(cluster code) 
estadd local em "1"
estadd local enet "\checkmark"
estadd local Municipalities " 198 "
estadd local established "Yes"
estimates store em2
restore 

preserve 
replace ln_horsepower_nz=-0.1 if horsepower==0
reghdfe ln_horsepower_nz bartik_post [aw=wei] ,a(year#laani50 $enet_12 year year#city year#town code)  vce(cluster code) 
estadd local em "0.1"
estadd local enet "\checkmark"
estadd local Municipalities " 198 "
estadd local established "Yes"
estimates store em3
restore 

preserve 
replace ln_horsepower_nz=0 if horsepower==0
reghdfe ln_horsepower_nz bartik_post [aw=wei] ,a(year#laani50 $enet_12 year year#city year#town code)  vce(cluster code) 
estadd local em "0"
estadd local enet "\checkmark"
estadd local Municipalities " 198 "
estadd local established "Yes"
estimates store em4 
restore 

esttab  bln_horsepower bntpln_horsepower bhlln_horsepower  bihs_horsepower bntpihs_horsepower bhlihs_horsepower   bln_horsepower_w bntpln_horsepower_w bhlln_horsepower_w em1 em2 em3 em4   ///
using   "$tables/DD_estimates_ln_horsepower.tex",  ///
mgroups("ln (Power Usage +1)" "IHS Power Usage" "ln (Power Usage +1, winsor)" "ln(Power Usage) if y $\ge$ 0, -x if y=0" ,   pattern(1 0 0 1  0 0 1  0 0 1 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
replace  keep(bartik_post  bartik_h_post bartik_l_post) nonotes ///
b(%9.3f) se(%9.3f) stats(N Municipalities established em, fmt(0 3) layout(@ @) ///
labels("N" "Municipalities" "Established" "Extensive margin (x)" ///
)) ///
label star(* .1 ** .05 *** .01) nodepvars nomtitle 
